﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class ajax_validUserInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (LoginOrLogout())
        {
            validUserInfo();
        }
        //Response.Write(false);
    }

    protected void validUserInfo()
    {
        string username = Request.QueryString["username"];
        string password = Request.QueryString["password"];
        //Int32 output;
        string UserInfoQuery = "SELECT TOP 1 * FROM UserList WHERE EmpID = '" + username + "' AND EmpPassword = '" + password + "'";
        //string UserInfoQuery = "SELECT count(*) FROM USERLIST WHERE EmpID = 62117 AND EmpPassword = '123'";
        DBOperate MyDB = new DBOperate();
        MyDB.SetCommandString(UserInfoQuery);
        OleDbDataReader reader = MyDB.ExecuteReader();
        if (!reader.HasRows) { Response.Write(Convert.ToInt32(0)); }
        while (reader.Read())
        {
            Session["EmpName"] = reader["EmpName"];
            Session["EmpID"] = reader["EmpID"];
            Session["GroupName"] = reader["GroupName"];
            Session["IsAdmin"] = reader["IsAdmin"];
            Session["userinfo"] = Session["EmpID"];
            Response.Write(Convert.ToInt32(reader.HasRows));
        }
        MyDB.CloseDB();
    }

    protected Boolean LoginOrLogout()
    {
        if (Request.QueryString["action"] == "logout")
        {
            Session.Clear();
            Response.Write("成功退出!");
            return false;
        }
        else
        {
            return true;
        }
    }


}
